/*
 * @Descripttion: 
 * @version: 
 * @@Company: DCIT-SH
 * @Author: 王富银
 * @Date: 2024-08-08 14:02:14
 * @LastEditors: Sunny Chen
 * @LastEditTime: 2024-08-21 11:30:08
 */

import { defineStore } from 'pinia'
import {ref} from 'vue';
import mapboxgl from 'mapbox-gl';
export const useMapStore = defineStore('map', {
  state:()=>{
    return {
      map:null,
      //存储marker
      markers:null,
      //画笔
      draw:null,
      controls:[],
    }
  },
  getters:{
    Map(){
      return this.map;
    },
    Marker(){
      return this.markers;
    },
    Draw(){
      return this.draw;
    },
    Controls(){
      return this.controls;
    }
  },
  actions:{
    setMap(map){
      return new Promise((reslove,reject)=>{
        this.map = map;
        reslove(map);
      })
    },
    setMarkers(markers){
      return new Promise((reslove,reject)=>{
        this.markers = markers.length ? markers : [];
        reslove(markers);
      })
    },
    setDraw(draw){
      return new Promise((resolve,reject)=>{
        this.draw = draw;
        resolve(draw);
      })
    },
    setControl(controls){
      return new Promise((reslove,reject)=>{
        if(!controls){
          reject("控件不能为null");
        }
        if(controls instanceof mapboxgl.Control){
          this.controls.push(controls);
          reslove(controls);
        }
      })
    }
  }
})

export const usePostStore = defineStore('post',()=>{
  const postAreaResult = ref(false);
  const updatePostAreaResult = (newVal)=>{
    postAreaResult.value = newVal;
  }
  const postCarResult = ref(false);
  const updatePostCarResult = (newVal)=>{
    postCarResult.value = newVal;
  }
  //轨迹查询时当前的车的编号
  const currentCarIdOfTrajectory = ref('XH002');
  //当前选中的上报故障的车辆
  const selectCarOfFault = ref(null);
  const updateSelectCarOfFault = (newVal)=>{
    selectCarOfFault.value = newVal;
  }
  //是否重新渲染故障列表
  const isRefreshFaultList = ref(false);
  const updateRefreshFaultList = (newVal)=>{
    isRefreshFaultList.value = newVal;
  }
  //是否进入数据中心页面
  const isEnterDataCenterView = ref(false);
  const updateEnterDataCenterView = (newVal)=>{
    isEnterDataCenterView.value = newVal;
  }

  //当前登录的人的name
  const currentLoginName = ref("");
  const updateCurrentLoginName = (newVal)=>{
    currentLoginName.value = newVal;
  }
  //当前登录的人的类别
  const currentLoginType = ref(0);
  const updateCurrentLoginType = (newVal)=>{
    currentLoginType.value = newVal;
  }
  return {
    postAreaResult,
    postCarResult,
    currentCarIdOfTrajectory,
    selectCarOfFault,
    isRefreshFaultList,
    isEnterDataCenterView,
    currentLoginName,
    currentLoginType,
    updateRefreshFaultList,
    updatePostAreaResult,
    updatePostCarResult,
    updateSelectCarOfFault,
    updateEnterDataCenterView,
    updateCurrentLoginName,
    updateCurrentLoginType,
  }
})
